<?php

require_once 'global.inc.php';

//check to see if they're logged in
if(isset($_SESSION['admin_logged_in'])) {
	header("Location: main.php");
}

$error = "";
$username = "";
$password = "";

//check to see if they've submitted the login form
if(isset($_POST['submit-login'])) {

	$username = $_POST['username'];
	$password = $_POST['password'];

	$userTools = new UserTools();
	if($userTools->login($username, $password)){
		//successful login, redirect them to a page
		header("Location: main.php");
	} else{
		$error = "Incorrect username or password. Please try again.";
	}
}
?>
<!DOCTYPE html>
<html>
	<?php include 'header.php';?>
	<body>
		<!-- Navigation start -->
		<div class="navbar navbar-inverse navbar-fixed-top">
			<div class="navbar-inner">
				<div class="container">

				</div>
			</div>
		</div>
		<!-- Navigation end -->

		<div class="container">
			<div class="row">
				<div class="span12">
					<h1>Administrator</h1>
				</div>
			</div>
			<div class="row">
				<div class="span12">
					<?php
					if($error != "")
					{
						echo $error."<br/>";
					}
					?>
					<form action="index.php" method="post">
						Username: <input type="text" name="username" value="<?php echo $username; ?>" /><br/>
						Password: <input type="password" name="password" value="<?php echo $password; ?>" /><br/>
						<input type="submit" value="Login" name="submit-login" />
					</form>
				</div>
			</div>
		</div>

		<?php include 'footer.php';?>
		<!-- Javascript -->
		<script src="js/jquery.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</body>
</html>